package com.hw.webflux.reactivedao;

import com.hw.webflux.model.User;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @program: spring-webflux
 * @description:
 * @author: hewei
 * @date: 2021-11-24 13:33
 **/

@Repository
public interface UserReactiveDao extends ReactiveSortingRepository<User,Long> {

    @Query("select * from t_user where name like CONCAT('%',:name,'%')")
    public Flux<User> findByName(String name);

    /**
     * 响应式的更新和新增操作支持不友好
     * 可以通过databaseClient工具进行操作
     */
    @Modifying
    @Query("update t_user set name = :name where id = :id")
    public Mono<Integer> updateNameById(Long id,String name);
}
